<?php

use think\Request;

/**
 * 记录接口传输数据
 * @param string $type
 * @param string $data
 */
function addApiLog($type='before', $data=''){
	$req = Request::instance();
	//可在目录
	$dir = $_SERVER['DOCUMENT_ROOT'].'/../runtime/apiLog/'.$req->controller().'/'.$req->action().'/';
	
	if(!is_dir($dir)){
		mkdir($dir,0777,true);
	}
	$log = '';
	if($type == 'before')
	{
		$log .= '=========='.date('Y-m-d H:i:s')."===========\r\n";
		$log .= "post数据：\r\n";
		$postData = input('post.');
		$log .= var_export($postData,true)."\r\n";
		
		$log .= "get数据：\r\n";
		$getData = input('get.');
		$log .= var_export($getData,true)."\r\n";
	}
	else
	{
		$log .= "返回数据：\r\n";
		$log .= var_export($data,true)."\r\n";
		$log .= '=========='.date('Y-m-d H:i:s')."===========\r\n";
	}
	file_put_contents($dir.date('Y-m-d').'.txt',$log."\r\n",FILE_APPEND);
}
